<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Performance</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>

<body>
<h1>Script Performance</h1>

<p>To maximize performance, avoid using SetFormat (except the <a href="../commands/SetFormat.htm#Fast">fast mode</a>) and include the following lines near the top of each script:</p>
<pre><a href="../commands/_NoEnv.htm">#NoEnv</a>
<a href="../commands/SetBatchLines.htm">SetBatchLines -1</a>
<a href="../commands/ListLines.htm">ListLines Off</a></pre>
<p>In addition, the following commands may also affect performance depending on the nature of the script: <a href="../commands/SendMode.htm">SendMode</a>, <a href="../commands/SetKeyDelay.htm">SetKeyDelay</a>, <a href="../commands/SetMouseDelay.htm">SetMouseDelay</a>, <a href="../commands/SetWinDelay.htm">SetWinDelay</a>, <a href="../commands/SetControlDelay.htm">SetControlDelay</a>, and <a href="../commands/SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>.</p>
<h3><strong>Built-in Performance Features</strong></h3>
<p>Each script is semi-compiled while it is being loaded and syntax-checked. In addition to reducing the memory consumed by the script, this also greatly improves runtime performance.</p>
<p>Here are the technical details of the optimization process (semi-compiling):</p>
<ul>
  <li>Input and output variables (when their names don't contain references to other variables) and <a href="../commands/GroupAdd.htm">group</a> names are resolved to memory addresses.</li>
  <li><a href="../commands/Loop.htm">Loops</a>, <a href="../commands/Block.htm">blocks</a>, <a href="../commands/IfEqual.htm">IFs</a>, and <a href="../commands/Else.htm">ELSEs</a> are given the memory addresses of their related jump-points in the script.</li>
  <li>The destination  of each <a href="../Hotkeys.htm">Hotkey</a>,<a href="../commands/Gosub.htm"> Gosub</a>, and <a href="../commands/Goto.htm">Goto</a> is resolved to a memory address unless it is a variable.</li>
  <li>Each command name is replaced by an address in a jump table.</li>
  <li>Each line is pre-parsed into a list of parameters, and each parameter is pre-parsed into a list of <a href="../Variables.htm">variables</a> (if any).</li>
  <li>Each <a href="../Variables.htm#Expressions">expression</a> is tokenized and converted from infix to postfix.</li>
  <li>Each reference to a <a href="../Variables.htm">variable</a> or <a href="../Functions.htm">function</a> is resolved to a memory address.</li>
  <li>Literal integers in expressions and math/comparison commands are replaced with binary integers.</li>
</ul>
<p>In addition, during script execution, binary numbers are cached in variables to avoid conversions to/from strings. See <a href="../commands/SetFormat.htm#Fast">SetFormat</a> for details.</p>
</body>
</html>
